<template>
  <view class="meeting">
    <!-- <Tabs :options="options" v-model="tab" class="tab" @change="onTabsChange" /> -->
    <view v-if="list.length > 0" class="cu-padding-top-30">
      <ShiftingDutyItem class="meetign-item" v-for="(item, index) in list" :key="index" :data="item" :type="tab" />
    </view>
    <Empty v-else />
  </view>
</template>

<script>
import store from '@/store'
import ShiftingDutyItem from './components/ShiftingDutyItem.vue'
import Tabs from './components/Tabs.vue'
import { getList, getListForFinish } from '@/api/duty-basic/duty-meeting'
import { getRecordList } from '@/api/duty-basic/duty-shifting.js'
import Empty from '@/components/cu-empty/index.vue'
export default {
  name: '',
  data() {
    return {
      staffId: store.getters.staffId,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        flowStatus: 0,
        isBacklog: 'Y'
      },
      options: [
        {
          value: 1,
          label: '当前交接班'
        },
        {
          value: 2,
          label: '交接班记录'
        }
      ],
      tab: 1,
      list: [],
      total: 0
    }
  },
  components: {
    Tabs,
    ShiftingDutyItem,
    Empty
  },
  methods: {
    async getList(isRefresh = true) {
      console.log(this.staffId)
      this.queryParams.flowStatus = this.tab === 1 ? 0 : 1
      const { rows = [], total } = await getRecordList(this.queryParams).finally(() => uni.stopPullDownRefresh())
      if (isRefresh) {
        this.list = rows
      } else {
        this.list = [...this.list, ...rows]
      }
      for (let t of this.list) {
        for (let i of t.taskInfoList) {
          if (this.staffId === i.actTaskUserId) {
            t.processTaskId = i.actTaskId
            t.flowNode = i.flowNode
            break
          }
        }
      }
      this.total = total
    },
    onTabsChange() {
      this.queryParams.pageNum = 1
      this.getList()
    }
  },
  onShow() {
    this.getList()
  },
  onNavigationBarButtonTap() {
    uni.navigateTo({
      url: '/pages/work/online-examination/record'
    })
  },
  onPullDownRefresh() {
    this.queryParams.pageNum = 1
    this.getList()
  },
  onReachBottom() {
    const { pageNum, pageSize } = this.queryParams
    if (pageNum * pageSize < this.total) {
      this.queryParams.pageNum += 1
      this.getList(false)
    }
  }
}
</script>

<style lang="scss" scoped>
.tab {
  margin-bottom: 20rpx;
}

.meetign-item {
  margin-bottom: 30rpx;
}
</style>
